class Account:
    def __init__(self):
        self.__balance = 100  # 私有变量

    def _pay(self, amount):
        if amount > 0:
            self.__balance -= amount  # 访问私有变量

# 创建Account类的实例
account = Account()

# 尝试调用受保护的方法
try:
    account._pay(30)
    print("调用受保护的方法成功。")
except AttributeError as e:
    print(f"出错了：{e}")

# 尝试访问私有变量
try:
    print(account.__balance)
except AttributeError as e:
    print(f"出错了：{e}")

# 正确的方式访问私有变量（不推荐）
try:
    print(account._Account__balance)
    print("通过名称改写访问私有变量成功。")
except AttributeError as e:
    print(f"出错了：{e}")
